import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0,
    history: []
  }),

  getters: {
    doubleCount: state => state.count * 2,
    isPositive: state => state.count > 0,
    isNegative: state => state.count < 0,
    historyCount: state => state.history.length
  },

  actions: {
    increment() {
      this.count++
      this.history.push(`增加: ${this.count}`)
    },

    decrement() {
      this.count--
      this.history.push(`减少: ${this.count}`)
    },

    incrementBy(amount) {
      this.count += amount
      this.history.push(`增加 ${amount}: ${this.count}`)
    },

    reset() {
      this.count = 0
      this.history.push(`重置: 0`)
    },

    clearHistory() {
      this.history = []
    }
  }
})
